package com.qinglei.recoup.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.system.domain.Bed;
import com.qinglei.recoup.system.domain.EventLogTest;
import com.qinglei.recoup.system.pojo.EventLogTestSearchParam;
import com.qinglei.recoup.system.pojo.HealthSearchParam;
import com.qinglei.recoup.system.pojo.HealthVO;
import com.qinglei.recoup.system.service.BedService;
import com.qinglei.recoup.system.service.EventLogTestService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author dqh
 */
@Controller
@RequestMapping("/event-log-test")
public class EventLogTestController {

    @Autowired
    private EventLogTestService eventLogTestService;

    @Autowired
    private BedService bedService;

    @GetMapping("/getEventLogTestPage")
    @ResponseBody
    public CommonRes<IPage<EventLogTest>> getEventLogTestPage(@Valid EventLogTestSearchParam param) {
        if(param!=null && param.getType()!=null && param.getType()==0){
            param.setType(null);
        }
        if(!StringUtils.isEmpty(param.getSnCode())){
            Bed bed = bedService.getBedBySn(param.getSnCode());
            if(bed!=null){
                param.setBedId(bed.getId());
            }

        }
        IPage<EventLogTest> eventLogTests = eventLogTestService.getEventLogTestPage(param);

        return CommonRes.ok(eventLogTests);
    }

    @GetMapping("/")
    public String index() {
        return "index";
    }

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @GetMapping("/logout")
    public String logout() {
        return "logout";
    }
}
